<%@page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!-- BEGIN HEADER -->
<div class="page-header navbar navbar-fixed-top">
	<!-- BEGIN HEADER INNER -->
	<div class="page-header-inner">
		<!-- BEGIN LOGO -->
		<div class="page-logo">
			<a> <img
				src="<%=request.getContextPath()%>/static/assets/admin/layout/img/logo.png"
				alt="logo" class="logo-default" />
			</a>
			<div class="menu-toggler sidebar-toggler hide">
				<!-- DOC: Remove the above "hide" to enable the sidebar toggler button on header -->
			</div>
		</div>
		<!-- END LOGO -->
		<!-- BEGIN RESPONSIVE MENU TOGGLER -->
		<a href="javascript:;" class="menu-toggler responsive-toggler"
			data-toggle="collapse" data-target=".navbar-collapse"> </a>
		<!-- END RESPONSIVE MENU TOGGLER -->
		<!-- BEGIN TOP NAVIGATION MENU -->
		<div class="top-menu">
			<ul class="nav navbar-nav pull-right">
				<li class="dropdown dropdown-user">
					<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true"> 
						<span class="username"> 你好！${sessionScope.user_alias}</span> 
						<i class="fa fa-angle-down"></i>
					</a>
					<ul class="dropdown-menu">
						<li><a class="btn default" href="#updatePwd"
							data-toggle="modal"> <i class="icon-lock"></i> 修改密码
						</a></li>
						<li>
							<a class="btn default" href="<%=request.getContextPath()%>/logout">
								<i class="icon-key"></i> 退出登录
							</a>
						</li>
					</ul>
				</li>
			</ul>
		</div>
	</div>
</div>
<!-- modal BEGIN -->
<div id="updatePwd" class="modal fade" tabindex="-1" aria-hidden="true">
	<div class="modal-dialog">
		<div class="portlet box blue">
			<div class="portlet-title">
				<div class="caption">
					<i class="fa fa-user"></i>账户管理
				</div>
				<div class="tools">
					修改个人密码
				</div>
			</div>
			<div class="portlet-body form">
				<div class="form-body">
					<table  style="margin: 3px" class="table table-striped table-hover table-bordered" id="userInfoTable2">
						<tr>
							<td>
								当前密码
							</td>
							<td>
								<input class="col-md-10" id="header_password_edit" type="password" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\~\!\@\#\$\%\^\&\*\_\+\-\=\.]/g,'')"></input>
								&nbsp;&nbsp;<font color="red">*</font>
							</td>
						</tr>
						<tr>
							<td>
								新密码
							</td>
							<td>
								<input class="col-md-10" id="header_password1_edit" type="password" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\~\!\@\#\$\%\^\&\*\_\+\-\=\.\,]/g,'')"></input>
								&nbsp;&nbsp;<font color="red">*</font>
							</td>
						</tr>
						<tr>
							<td>
								重输密码
							</td>
							<td>
								<input class="col-md-10" id="header_password2_edit" type="password" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\~\!\@\#\$\%\^\&\*\_\+\-\=\.\,]/g,'')"></input>
								&nbsp;&nbsp;<font color="red">*</font>
							</td>
						</tr>
					</table>
				</div>
				<div class="form-actions right">
					<button type="button" data-dismiss="modal" class="btn default">返回</button>
					<button id="header_save_edit_user_btn" type="button" class="btn green">提交</button>
				</div>		
			</div>
		</div>
	</div>
</div>
<!-- modal END -->
<script>
$.ajaxSetup({
	success:function(data){ 
	},
	complete:function(XMLHttpRequest,textStatus){
		if(XMLHttpRequest.responseText.indexOf('pageTologin')>-1){
			location.reload();
			window.location.href="<%=request.getContextPath()%>/login";
		}
	}
});
$("#changePwd").click(function(){
	$("#header_edit_user").modal("show");
	$("#header_password_edit").val("");  //原密码 
    $("#header_password1_edit").val(""); //新密码
    $("#header_password2_edit").val(""); //确认密码
	
});

$("#header_save_edit_user_btn").click(function(){
	if("" == $("#header_password_edit").val()){
		alert("请输入原密码！");
		return;
	} 
	if("" == $("#header_password1_edit").val()){
		alert("请输入新密码！");
		return;
	}
	if("" == $("#header_password2_edit").val()){
		alert("请输入确认密码！");
		return;
	}
	if($("#header_password1_edit").val() != $("#header_password2_edit").val()){
		alert("两次输入密码不一致！");
		return;
	}
	$.post("<%=request.getContextPath()%>/user/updateUserPwd",
		{
			passWordOld : $("#header_password_edit").val(),
			passWordNew : $("#header_password1_edit").val()
		}, function(result) {
			if(result == -1){
				alert("系统内部错误,请与管理员联系！");
			}else if(result == 0){
				alert("修改成功,请重新登陆！");
				$("#header_edit_user").modal("hide");
				$("#header_password_edit").val("");
				$("#header_password1_edit").val("");
				$("#header_password2_edit").val("");
				location.href = "<%=request.getContextPath()%>/logout";
			} else if (result == 1) {
				alert("您的登陆凭证已失效,请重新登陆后在试！");
			} else if (result == 2) {
				alert("原密码输入错误，请验证后在试！");
				$("#header_password_edit").focus();
			}
		}
	);
});
</script>
<!-- END HEADER -->